home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / signal / c / sigaction < prev    next >
Text File  |  1996-11-09  |  2KB  |  62 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/signal/c/RCS/sigaction,v $
  4.  * $Date: 1996/10/30 22:04:51 $
  5.  * $Revision: 1.1 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: sigaction,v $
  10.  * Revision 1.1  1996/10/30 22:04:51  unixlib
  11.  * Initial revision
  12.  *
  13.  ***************************************************************************/
  14.  
  15. static const char rcs_id[] = "$Id: sigaction,v 1.1 1996/10/30 22:04:51 unixlib Rel $";
  16.  
  17. /* sigaction.c: Written by Nick Burrett, 31 August 1996.  */
  18.  
  19. #include <errno.h>
  20. #include <stddef.h>
  21. #include <signal.h>
  22. #include <unixlib/sigstate.h>
  23. #include <sys/unix.h>
  24.  
  25. /* Set up a new action for the signal 'sig' specified by 'act'.
  26.    The old action is returned in 'oact'.
  27.  
  28.    If oact is null, no information is returned.
  29.    If act is null, the signal action remains unchanged, you can then
  30.    read the action currently associated with the signal.
  31.  
  32.    Returns zero on sucess, -1 on failure.  */
  33.  
  34. int sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  35. {
  36.   struct unixlib_sigstate *ss = &__u->sigstate;
  37.  
  38.   if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP)
  39.     {
  40.       /* Signal number was out of range, or a SIGKILL or SIGSTOP
  41.          was trapped.  */
  42.       errno = EINVAL;
  43.       return -1;
  44.     }
  45.  
  46.   if (oact != NULL)
  47.     {
  48.       oact->sa_handler = ss->actions[sig].sa_handler;
  49.       oact->sa_mask = ss->actions[sig].sa_mask;
  50.       oact->sa_flags = ss->actions[sig].sa_flags;
  51.     }
  52.  
  53.   if (act != NULL)
  54.     {
  55.       ss->actions[sig].sa_handler = act->sa_handler;
  56.       ss->actions[sig].sa_mask = act->sa_mask;
  57.       ss->actions[sig].sa_flags = act->sa_flags;
  58.     }
  59.  
  60.   return 0;
  61. }
  62.